package com.cqut.ktpspring.controller;

import com.cqut.ktpspring.pojo.Comment;
import com.cqut.ktpspring.pojo.Result;
import com.cqut.ktpspring.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Slf4j
@RestController
public class CommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("/comment")
    public Result comment(@RequestBody Comment comment) {
        log.info("学生讨论{}",comment);
        commentService.comment(comment);
        return Result.success(comment);
    }

    @GetMapping("/getComments")
    public Result getComments(@RequestParam String workId) {
        log.info("查询某次作业的所有讨论{}",workId);
        List<Comment> commentList=commentService.getComments(workId);
        return Result.success(commentList);
    }
}
